package com.jr.mapper;

import com.jr.pojo.PetDiary;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface PetDiaryMapper {

    @Select("SELECT * FROM pet_diaries WHERE diary_id = #{diaryId}")
    PetDiary selectById(Integer diaryId);

    @Select("SELECT * FROM pet_diaries WHERE order_id = #{orderId} ORDER BY entry_date DESC")
    List<PetDiary> selectByOrderId(Integer orderId);

    @Select("SELECT * FROM pet_diaries WHERE provider_id = #{providerId} ORDER BY entry_date DESC")
    List<PetDiary> selectByProviderId(Integer providerId);

    @Insert("INSERT INTO pet_diaries (order_id, provider_id, entry_date, title, content, photos, mood, appetite, activity_level, created_at, updated_at) " +
            "VALUES (#{orderId}, #{providerId}, #{entryDate}, #{title}, #{content}, #{photos}, #{mood}, #{appetite}, #{activityLevel}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "diaryId")
    int insertPetDiary(PetDiary petDiary);

    @Update("UPDATE pet_diaries SET title=#{title}, content=#{content}, photos=#{photos}, mood=#{mood}, " +
            "appetite=#{appetite}, activity_level=#{activityLevel}, updated_at=#{updatedAt} WHERE diary_id=#{diaryId}")
    int updatePetDiary(PetDiary petDiary);

    @Delete("DELETE FROM pet_diaries WHERE diary_id = #{diaryId}")
    int deletePetDiary(Integer diaryId);

    @Select("SELECT * FROM pet_diaries WHERE order_id = #{orderId} AND entry_date = #{entryDate}")
    PetDiary selectByOrderIdAndDate(@Param("orderId") Integer orderId, @Param("entryDate") String entryDate);
}
